package top.yokey.android;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.AppCompatEditText;
import androidx.appcompat.widget.AppCompatTextView;

public class LoginActivity extends AppCompatActivity {

    private AppCompatEditText mobileEditText;
    private AppCompatEditText passwordEditText;
    private AppCompatTextView loginTextView;
    private AppCompatTextView registerTextView;
    private View mobileView, passwordView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        System.out.println("onCreate");
        setContentView(R.layout.activity_login);
        mobileEditText = findViewById(R.id.mobileEditText);
        passwordEditText = findViewById(R.id.passwordEditText);
        loginTextView = findViewById(R.id.loginTextView);
        registerTextView=findViewById(R.id.registerTextView);
        mobileView = findViewById(R.id.mobileView);
        passwordView = findViewById(R.id.passwordView);

        mobileEditText.setOnFocusChangeListener((view, b) -> {
            if (b) {
                mobileView.setBackgroundResource(R.color.primary);
                passwordView.setBackgroundResource(R.color.textHint);
            }
        });

        passwordEditText.setOnFocusChangeListener((view, b) -> {
            if (b) {
                mobileView.setBackgroundResource(R.color.textHint);
                passwordView.setBackgroundResource(R.color.primary);
            }
        });

        loginTextView.setOnClickListener(view -> {
            System.out.println("账号编辑框内容为:" + mobileEditText.getText().toString());
            System.out.println("密码编辑框内容为:" + passwordEditText.getText().toString());
        });

        registerTextView.setOnClickListener(view -> {
            //activity之间的跳转 使用intent，一定要确保目标activity已经在manifests文件注册
            Intent intent = new Intent(LoginActivity.this,RegisterActivity.class);
            startActivity(intent);
        });

    }

}
